describe('parseAnalyze', function() {
    describe('regex', function() {
        it('rKey should match the object path and blank strings', function() {
            expect("abc.dd").toMatch(rKey)
            expect(" ").toMatch(rKey)
            expect("  ").not.toMatch(rKey)
            expect("	").not.toMatch(rKey)
            expect("").toMatch(rKey)
        })

        // it("isTextBind match the right string", function() {
        //     expect("jc-bind  ccc").toMatch(isTextBind)
        //     expect("jc-bind ccc".replace(isTextBind, "")).toEqual("ccc")

        // })
    })

    describe('filters', function() {
        describe("sampleMap", function() {
            var argToMap, input, sm = jc.filters.sampleMap;
            beforeEach(function() {
                argToMap = ["a", "aV", "b", "bV", "true", "trueV", "false", "falseV", "1", "1V"]
            })
            it("can return the right map value by the input", function() {

                expect(sm.apply(1, ["a"].concat(argToMap))).toBe("aV")
                expect(sm.apply(1, [true].concat(argToMap))).toBe("trueV")
                expect(sm.apply(1, [1].concat(argToMap))).toBe("1V")
            })
        })
    })

    describe("repeat tag", function() {
        var div1, data1, data2;

        beforeEach(function() {
            jasmine.clock().install()
            $.ajax = mocka.mockView()
            div1 = setFixtures("<div id='father_1'></div>")
            data1 = {
                elems: [1, 3, 4, 5, 6],
                objs: [{
                    key: "d1",
                    value: "v1"
                }, {
                    key: "d2",
                    value: "v2"
                }]
            }

            data2 = {
                e1: [{
                        e2: [
                            1, 2, 3
                        ],
                        data: "d11"
                    }, {
                        e2: [4, 5, 6],
                        data: "d12"
                    }

                ],
                obj1: [{
                    obj2: [{
                        key: "key11",
                        value: "value11"
                    }, {
                        key: "key12",
                        value: "value12"
                    }],
                    data: "obj11"
                }, {
                    obj2: [{
                        key: "key21",
                        value: "value21"
                    }, {
                        key: "key22",
                        value: "value22"
                    }],
                    data: "obj12"
                }]
            }

        })
        afterEach(function() {
            jasmine.clock().uninstall();
            session = {};
        })
        it("should render sample data right", function() {

            jc.render(data1, "test_repeat_tag_1", div1, function(th) {
                var elemUl = div1.find("#elem")
                var objUl = div1.find("#obj")
                expect(elemUl.children().length).toBe(data1.elems.length)
                for (var i = 0; i < data1.elems.length; i++) {
                    expect(elemUl.children().eq(i)).toContainText(data1.elems[i])
                }
                data1.objs.forEach(function(obj, index) {
                    var objElem = objUl.children().eq(index)
                    expect(objElem).toHaveAttr("key", obj.key)
                    expect(objElem).toContainText(obj.value)
                })

            })
        })
        it("should render nested array data right", function() {
            jc.render(data2, "test_repeat_tag_2", div1, function(th) {
                var e1Div = div1.find("#e1")
                var e1dataDiv = e1Div.find("h3")
                data2.e1.forEach(function(e1, index) {
                    var elem = e1dataDiv.eq(index)
                    expect(elem).toContainText(e1.data);
                    var test = elem.nextUntil("h3")
                    var e2Span = elem.nextUntil("h3").find(".e2");
                    var e1Span = elem.nextUntil("h3").find(".e1");
                    e1.e2.forEach(function(e2, i2) {
                        expect(e2Span.eq(i2)).toContainText(e2)
                        expect(e1Span.eq(i2)).toContainText(e1.data)
                    })

                })
            })
        })

        it("should render nested obj data right", function() {
            jc.render(data2, "test_repeat_tag_3", div1, function(th) {
                var obj1H3 = div1.find("h3")
                data2.obj1.forEach(function(o1, i1) {
                    var elem = obj1H3.eq(i1)
                    var o2Span = elem.nextUntil("h3").find(".e2")
                    var o1Span = elem.nextUntil("h3").find(".e1")
                    expect(elem).toContainText(o1.data)
                    o1.obj2.forEach(function(o2, i2) {
                        expect(o2Span.eq(i2)).toContainText(o2.value)
                        expect(o2Span.eq(i2)).toHaveAttr("key", o2.key)
                        expect(o1Span.eq(i2)).toContainText(o1.data)
                    })

                })
            })
        })

        it("can  transfer the element ", function() {
            jc.render(data1, "test_repeat_tag_1", div1, function(th) {
                var arr = data1.elems
                var temData = arr[0]
                arr.set(0, arr[1])
                arr.set(1, temData)
                var lis = div1.find("#elem li")
                expect(lis.eq(0).html()).toBe("" + 3)
                expect(lis.eq(1).html()).toBe("" + 1)
            })

        })
    })
    describe('foreach',function(){
        it("should render sample array data right",function(){
            
        })
    })


});